<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="地区名字" prop="areaId">
        <el-select
          v-model="queryParams.areaId"
          placeholder="请选择"
          @change="remarkAllchange"
          style="width: 120px"
        >
          <el-option
            v-for="item in remark"
            :key="item.index"
            :label="item.areaName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目名字" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入项目名字"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="项目状态" prop="itemStatus">
        <el-select
          v-model="queryParams.itemStatus"
          placeholder="请选择"
          @change="remarkAllchange"
          style="width: 120px"
        >
          <el-option
            v-for="item in ailist"
            :key="item.index"
            :label="item.itemStatus"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="甲方单位名字" prop="customerCompanyName">
        <el-input
          v-model="queryParams.customerCompanyName"
          placeholder="请输入甲方单位名字"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目审核状态" prop="auditStatus">
        <el-select
          v-model="queryParams.auditStatus"
          placeholder="请选择"
          @change="remarkAllchange"
          style="width: 120px"
        >
          <el-option
            v-for="item in bilist"
            :key="item.index"
            :label="item.auditStatus"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['item:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['item:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="roleList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" prop="id" width="60" />

      <el-table-column
        label="项目名称"
        align="center"
        prop="itemName"
        :show-overflow-tooltip="true"
        width="300"
      />

      <el-table-column prop="itemStatus" label="状态" width="80">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.project_status"
            :value="scope.row.itemStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="区域"
        align="center"
        prop="areaName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="状态时间"
        align="center"
        prop="itemStatusTime"
        :show-overflow-tooltip="true"
        width="150"
      />
      <el-table-column
        label="金额"
        align="center"
        prop="itemAmount"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="备注"
        align="center"
        prop="itemRemark"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="甲方单位名字"
        align="center"
        prop="customerCompanyName"
        :show-overflow-tooltip="true"
        width="180"
      />
      <el-table-column
        prop="workUnit"
        label="测量单位"
        width="80"
        align="center"
      >
        <template slot-scope="scope">
          <div v-for="(item, index) in scope.row.workUnit" :key="index">
            {{ item.name }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="commissionType" label="提成类型" width="80">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.poject_status_p"
            :value="scope.row.commissionType"
          />
        </template>
      </el-table-column>

      <el-table-column
        label="提成数值"
        align="center"
        prop="commissionNumber"
        :show-overflow-tooltip="true"
      />

      <el-table-column
        label="申请金额"
        align="center"
        prop="itemAmountUpdate"
        :show-overflow-tooltip="true"
      />
      <el-table-column prop="auditAmountStatus" label="金额状态" width="80">
        <template slot-scope="scope">
          <div v-if="scope.row.itemAmountUpdate != 0">
            <dict-tag
              :options="dict.type.poject_price_status"
              :value="scope.row.auditAmountStatus"
            />
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="auditAmountFailCause"
        label="金额拒绝原因"
        width="180"
      >
        <template slot-scope="scope">
          <div v-if="scope.row.auditAmountStatus == 2">
            {{ scope.row.auditAmountFailCause }}
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="创建人名字"
        align="center"
        prop="createUserName"
        :show-overflow-tooltip="true"
        width="180"
      />
      <el-table-column prop="auditStatus" label="提成状态" width="80">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.poject_auditstatus"
            :value="scope.row.auditStatus"
          />
        </template>
      </el-table-column>

      <el-table-column
        label="提成拒绝原因"
        align="center"
        prop="auditFailCause"
        :show-overflow-tooltip="true"
        width="180"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        width="420"
        fixed="right"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['item:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleInfo(scope.row)"
            v-hasPermi="['item:audit:item']"
            >提成审核</el-button
          >
          <!-- 0未审核 1审核通过 2审核驳回 -->
          <el-button
            size="mini"
            type="text"
            @click="handlePrice(scope.row)"
            v-hasPermi="['item:update:amount']"
            >修改金额</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handlePriceAudit(scope.row)"
            :disabled="scope.row.itemAmountUpdate == 0 ? true : false"
            v-hasPermi="['item:audit:amount']"
            >金额审核</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleReimburse(scope.row)"
            v-hasPermi="['reimburse:export']"
            >报销</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleOut(scope.row)"
            v-hasPermi="['item:out:list']"
            >项目外包</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleAllyes(scope.row)"
            v-hasPermi="['item:finish']"
            >项目完成</el-button
          >

          <el-button
            :disabled="
              scope.row.itemAudit.auditStatus2 == 1 ||
              (scope.row.itemAudit.auditStatus2 == 0 &&
                scope.row.itemAudit.auditStatus1 == 1)
            "
            size="mini"
            type="text"
            @click="addl(scope.row)"
            v-hasPermi="['item:set:commission']"
            >提成设置</el-button
          >

          <el-button
            size="mini"
            type="text"
            @click="look(scope.row)"
            v-hasPermi="['item:set:look']"
            >查看项目</el-button
          >
          <el-button size="mini" type="text" @click="lookxm(scope.row)"
            >项目明细</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加修改项目列表 -->
    <el-dialog
      title="项目详情"
      :visible.sync="openLook"
      width="800px"
      append-to-body
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="140px"
        disabled
      >
        <el-row>
          <el-form-item label="项目名字" prop="itemName">
            <el-input v-model="form.itemName" placeholder="请输入项目名字" />
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="地区名字" prop="areaId">
              <el-select
                v-model="form.areaId"
                placeholder="请选择"
                @change="remarkAllchange"
              >
                <el-option
                  v-for="item in remark"
                  :key="item.index"
                  :label="item.areaName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目金额" prop="itemAmount">
              <el-input
                v-model="form.itemAmount"
                type="number"
                oninput="value = value.replace(/[^0-9]/g,'' )"
                placeholder="请输入项目金额"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="甲方单位名字" prop="customerCompanyName">
              <el-input
                v-model="form.customerCompanyName"
                placeholder="请输入甲方单位名字"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12"> </el-col>
        </el-row>
        <el-row>
          <el-form-item label="工作单位及价格" prop="temppricelist">
            <el-select
              v-model="form.temppricelist"
              placeholder="请选择"
              multiple
              value-key="id"
              @change="unitcahnge"
            >
              <el-option
                v-for="item in unitlist"
                :key="item.index"
                :label="item.unitName"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>

          <div v-for="(item, index) in pricelist" :key="index">
            <el-form-item :label="item.name" width="100" prop="price">
              <el-input v-model="item.price" placeholder="请输入价格" />
            </el-form-item>
          </div>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="提成类型" prop="commissionType">
              <el-select
                v-model="form.commissionType"
                placeholder="请选择"
                @change="postChange"
              >
                <el-option
                  v-for="item in commissionTypelist"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="Numbertitle" prop="commissionNumber">
              <el-input
                type="number"
                oninput="value = value.replace(/[^0-9]/g,'' )"
                v-model="form.commissionNumber"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="项目负责人" prop="k100_list">
              <el-select
                v-model="form.k100_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k100', 1)"
              >
                <el-option
                  v-for="item in allList"
                  :key="item.index"
                  :label="item.nickName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合作方列表" prop="itemCooperateList">
              <el-select
                v-model="form.itemCooperateList"
                multiple
                value-key="id"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in hezlist"
                  :key="item.index"
                  :label="item.nickName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="测绘岗位负责人" prop="k211_list">
              <el-select
                v-model="form.k211_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k211', 2, 1, 1)"
              >
                <el-option
                  v-for="item in allList"
                  :key="item.index"
                  :label="item.nickName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="内部负责人" prop="k212_list">
              <el-select
                v-model="form.k212_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k212', 2, 1, 2)"
              >
                <el-option
                  v-for="item in allList"
                  :key="item.index"
                  :label="item.nickName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="外部负责人" prop="k213_list">
              <el-select
                v-model="form.k213_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k213', 2, 1, 3)"
              >
                <el-option
                  v-for="item in allList"
                  :key="item.index"
                  :label="item.nickName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="设计岗位负责人" prop="k221_list">
              <el-select
                v-model="form.k221_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k221', 2, 2, 1)"
              >
                <el-option
                  v-for="item in allList"
                  :key="item.index"
                  :label="item.nickName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="内部负责人" prop="k222_list">
              <el-select
                v-model="form.k222_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k222', 2, 2, 2)"
              >
                <el-option
                  v-for="item in allList"
                  :key="item.index"
                  :label="item.nickName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="外部负责人" prop="k223_list">
              <el-select
                v-model="form.k223_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k223', 2, 2, 3)"
              >
                <el-option
                  v-for="item in allList"
                  :key="item.index"
                  :label="item.nickName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="项目备注" prop="itemRemark">
          <el-input
            type="textarea"
            v-model="form.itemRemark"
            placeholder="请输入项目备注"
          />
        </el-form-item>
      </el-form>

      <div v-if="itemAudit != null">
        <div>提成审核信息：</div>
        <el-col :span="24">
          <div v-if="itemAudit.auditStatus1 == 1" class="text">
            副经理：审核通过 时间：{{ itemAudit.auditTime1 }}
          </div>
          <div v-if="itemAudit.auditStatus1 == 2" class="text">
            副经理：审核驳回 时间：{{ itemAudit.auditTime1 }} 驳回原因：{{
              itemAudit.auditFailCause1
            }}
          </div>
          <div v-if="itemAudit.auditStatus2 == 1" class="text">
            总经理：审核通过 时间：{{ itemAudit.auditTime2 }}
          </div>
          <div v-if="itemAudit.auditStatus2 == 2" class="text">
            总经理：审核驳回 时间：{{ itemAudit.auditTime2 }} 驳回原因：{{
              itemAudit.auditFailCause2
            }}
          </div>
        </el-col>
      </div>

      <div v-if="itemAmountAudit != null">
        <div>金额审核信息：</div>
        <el-col :span="24">
          <div v-if="itemAmountAudit.auditStatus1 == 1" class="text">
            副经理：审核通过 时间：{{ itemAmountAudit.auditTime1 }}
          </div>
          <div v-if="itemAmountAudit.auditStatus1 == 2" class="text">
            副经理：审核驳回 时间：{{ itemAmountAudit.auditTime1 }} 驳回原因：{{
              itemAmountAudit.auditFailCause1
            }}
          </div>
          <div v-if="itemAmountAudit.auditStatus2 == 1" class="text">
            总经理：审核通过 时间：{{ itemAmountAudit.auditTime2 }}
          </div>
          <div v-if="itemAmountAudit.auditStatus2 == 2" class="text">
            总经理：审核驳回 时间：{{ itemAmountAudit.auditTime2 }} 驳回原因：{{
              itemAmountAudit.auditFailCause2
            }}
          </div>
        </el-col>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加修改项目列表 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="140px"
        :disabled="isdisabled"
      >
        <el-row>
          <el-form-item label="项目名字" prop="itemName">
            <el-input v-model="form.itemName" placeholder="请输入项目名字" />
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="地区名字" prop="areaId">
              <el-select
                v-model="form.areaId"
                placeholder="请选择"
                @change="remarkAllchange"
              >
                <el-option
                  v-for="item in remark"
                  :key="item.index"
                  :label="item.areaName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目金额" prop="itemAmount">
              <el-input
                :disabled="isprice"
                v-model="form.itemAmount"
                type="number"
                oninput="value = value.replace(/[^0-9]/g,'' )"
                placeholder="请输入项目金额"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="甲方单位名字" prop="customerCompanyName">
              <el-input
                v-model="form.customerCompanyName"
                placeholder="请输入甲方单位名字"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12"> </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="项目负责人" prop="k100_list">
              <el-select
                v-model="form.k100_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k100', 1)"
              >
                <el-option
                  v-for="item in ulist"
                  :key="item.index"
                  :label="item.userName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合作方列表" prop="itemCooperateList">
              <el-select
                v-model="form.itemCooperateList"
                multiple
                value-key="id"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in hezlist"
                  :key="item.index"
                  :label="item.nickName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="测绘岗位负责人" prop="k211_list">
              <el-select
                v-model="form.k211_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k211', 2, 1, 1)"
              >
                <el-option
                  v-for="item in ulist"
                  :key="item.index"
                  :label="item.userName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="内部负责人" prop="k212_list">
              <el-select
                v-model="form.k212_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k212', 2, 1, 2)"
              >
                <el-option
                  v-for="item in ulist"
                  :key="item.index"
                  :label="item.userName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="外部负责人" prop="k213_list">
              <el-select
                v-model="form.k213_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k213', 2, 1, 3)"
              >
                <el-option
                  v-for="item in ulist"
                  :key="item.index"
                  :label="item.userName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="设计岗位负责人" prop="k221_list">
              <el-select
                v-model="form.k221_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k221', 2, 2, 1)"
              >
                <el-option
                  v-for="item in ulist"
                  :key="item.index"
                  :label="item.userName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="内部负责人" prop="k222_list">
              <el-select
                v-model="form.k222_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k222', 2, 2, 2)"
              >
                <el-option
                  v-for="item in ulist"
                  :key="item.index"
                  :label="item.userName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="外部负责人" prop="k223_list">
              <el-select
                v-model="form.k223_list"
                multiple
                value-key="id"
                placeholder="请选择"
                @change="allchange($event, 'k223', 2, 2, 3)"
              >
                <el-option
                  v-for="item in ulist"
                  :key="item.index"
                  :label="item.userName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="项目备注" prop="itemRemark">
          <el-input
            type="textarea"
            v-model="form.itemRemark"
            placeholder="请输入项目备注"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <div>
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </div>
    </el-dialog>
    <!-- 提成添加 审核 -->
    <el-dialog
      :title="titletc"
      :visible.sync="openTC"
      width="600px"
      append-to-body
    >
      <el-row v-if="formtc.isdisabled">
        <el-col :span="24">
          <div v-if="itemAudit.auditStatus1 == 1" class="text">
            副经理：审核通过 时间：{{ itemAudit.auditTime1 }}
          </div>
          <div v-if="itemAudit.auditStatus1 == 2" class="text">
            副经理：审核驳回 时间：{{ itemAudit.auditTime1 }} 驳回原因：{{
              itemAudit.auditFailCause1
            }}
          </div>
          <div v-if="itemAudit.auditStatus2 == 1" class="text">
            总经理：审核通过 时间：{{ itemAudit.auditTime2 }}
          </div>
          <div v-if="itemAudit.auditStatus2 == 2" class="text">
            总经理：审核驳回 时间：{{ itemAudit.auditTime2 }} 驳回原因：{{
              itemAudit.auditFailCause2
            }}
          </div>
        </el-col>
      </el-row>
      <el-form
        ref="formtc"
        :model="formtc"
        :rules="rulestc"
        label-width="140px"
        :disabled="formtc.isdisabled"
      >
        <el-row>
          <el-form-item label="测绘岗位" prop="temppricelist">
            <el-select
              v-model="formtc.temppricelist"
              placeholder="请选择"
              multiple
              value-key="id"
              @change="unitcahnge"
            >
              <el-option
                v-for="item in unitlist"
                :key="item.index"
                :label="item.unitName"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>

          <div v-for="(item, index) in pricelist" :key="index">
            <el-form-item :label="item.name" width="100" prop="price">
              <el-input v-model="item.price" placeholder="请输入价格" />
            </el-form-item>
          </div>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="设计岗位" prop="commissionType">
              <el-select
                v-model="formtc.commissionType"
                placeholder="请选择"
                @change="postChange"
              >
                <el-option
                  v-for="item in commissionTypelist"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="Numbertitle" prop="commissionNumber">
              <el-input
                type="number"
                oninput="value = value.replace(/[^0-9]/g,'' )"
                v-model="formtc.commissionNumber"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-form ref="form1" :model="form1" :rules="rules1" label-width="140px">
        <div
          v-hasRole="['fuzong', 'admin']"
          v-if="itemAudit.auditStatus1 == 0 && formtc.isdisabled"
        >
          <el-form-item label="审核状态" prop="auditStatus1">
            <el-radio-group
              v-model="form1.auditStatus1"
              @change="audit($event, 1)"
            >
              <el-radio
                v-for="dict in auditList"
                :key="dict.name"
                :label="dict.id"
                >{{ dict.name }}</el-radio
              >
            </el-radio-group>
          </el-form-item>
          <el-form-item label="驳回原因" prop="auditFailCause1">
            <el-input
              v-model="form1.auditFailCause1"
              placeholder="请输入驳回原因"
            />
          </el-form-item>
        </div>
      </el-form>

      <el-form ref="form2" :model="form2" :rules="rules2" label-width="140px">
        <div
          v-hasRole="['manager', 'admin']"
          v-if="itemAudit.auditStatus2 == 0 && formtc.isdisabled"
        >
          <el-form-item label="审核状态" prop="auditStatus2">
            <el-radio-group
              v-model="form2.auditStatus2"
              @change="audit($event, 2)"
            >
              <el-radio
                v-for="dict in auditList"
                :key="dict.name"
                :label="dict.id"
                >{{ dict.name }}</el-radio
              >
            </el-radio-group>
          </el-form-item>
          <el-form-item label="驳回原因" prop="auditFailCause2">
            <el-input
              v-model="form2.auditFailCause2"
              placeholder="请输入驳回原因"
            />
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          v-if="itemAudit.auditStatus1 == 0 && formtc.isdisabled"
          v-hasRole="['fuzong']"
          @click="submitForm1"
          >副总经理提交审核</el-button
        >
        <el-button
          type="primary"
          v-if="itemAudit.auditStatus2 == 0 && formtc.isdisabled"
          v-hasRole="['manager']"
          @click="submitForm2"
          >总经理提交审核</el-button
        >
        <el-button
          v-if="!formtc.isdisabled"
          type="primary"
          @click="submitFormtcheng"
          >提交</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 金额修改-->
    <el-dialog
      title="项目金额更改"
      :visible.sync="open1"
      width="500px"
      append-to-body
    >
      <el-form ref="form3" :model="form3" :rules="rules3" label-width="140px">
        <el-form-item label="项目金额" prop="price">
          <el-input
            disabled
            type="number"
            v-model="form3.price"
            placeholder="请输入"
          />
        </el-form-item>

        <el-form-item label="修改金额" prop="itemAmountUpdate">
          <el-input
            type="number"
            oninput="value = value.replace(/[^0-9]/g,'' )"
            v-model="form3.itemAmountUpdate"
            placeholder="请输入修改金额"
          />
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormPrices">提交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 金额审核-->
    <el-dialog
      title="项目金额审核"
      :visible.sync="open2"
      width="500px"
      append-to-body
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="140px"
        :disabled="isdisabled"
      >
        <div>
          <div v-if="itemAmountAudit.auditStatus1 == 1" class="text">
            副经理：审核通过 时间：{{ itemAmountAudit.auditTime1 }}
          </div>
          <div v-if="itemAmountAudit.auditStatus1 == 2" class="text">
            总经理：审核驳回 时间：{{ itemAmountAudit.auditTime1 }} 驳回原因：{{
              itemAmountAudit.auditFailCause1
            }}
          </div>
          <div v-if="itemAmountAudit.auditStatus2 == 1" class="text">
            总经理：审核通过 时间：{{ itemAmountAudit.auditTime2 }}
          </div>
          <div v-if="itemAmountAudit.auditStatus2 == 2" class="text">
            总经理：审核驳回 时间：{{ itemAmountAudit.auditTime2 }} 驳回原因：{{
              itemAmountAudit.auditFailCause2
            }}
          </div>
        </div>
        <el-form-item label="项目金额" prop="itemAmount">
          <el-input
            disabled
            type="number"
            v-model="form.itemAmount"
            placeholder="请输入"
          />
        </el-form-item>

        <el-form-item label="修改金额" prop="itemAmountUpdate">
          <el-input
            disabled
            type="number"
            v-model="form.itemAmountUpdate"
            placeholder="请输入修改金额"
          />
        </el-form-item>
      </el-form>

      <el-form ref="form1" :model="form1" :rules="rules1" label-width="140px">
        <div
          v-hasRole="['fuzong', 'admin']"
          v-if="itemAmountAudit.auditStatus1 == 0"
        >
          <el-form-item label="审核状态" prop="auditStatus1">
            <el-radio-group
              v-model="form1.auditStatus1"
              @change="audit($event, 1)"
            >
              <el-radio
                v-for="dict in auditList"
                :key="dict.name"
                :label="dict.id"
                >{{ dict.name }}</el-radio
              >
            </el-radio-group>
          </el-form-item>
          <el-form-item label="驳回原因" prop="auditFailCause1">
            <el-input
              v-model="form1.auditFailCause1"
              placeholder="请输入驳回原因"
            />
          </el-form-item>
        </div>
      </el-form>

      <el-form ref="form2" :model="form2" :rules="rules2" label-width="140px">
        <div
          v-hasRole="['manager', 'admin']"
          v-if="itemAmountAudit.auditStatus2 == 0"
        >
          <el-form-item label="审核状态" prop="auditStatus2">
            <el-radio-group
              v-model="form2.auditStatus2"
              @change="audit($event, 2)"
            >
              <el-radio
                v-for="dict in auditList"
                :key="dict.name"
                :label="dict.id"
                >{{ dict.name }}</el-radio
              >
            </el-radio-group>
          </el-form-item>
          <el-form-item label="驳回原因" prop="auditFailCause2">
            <el-input
              v-model="form2.auditFailCause2"
              placeholder="请输入驳回原因"
            />
          </el-form-item>
        </div>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          v-if="itemAmountAudit.auditStatus1 == 0"
          v-hasRole="['fuzong']"
          @click="submitForm3"
          >副总经理提交审核</el-button
        >
        <el-button
          type="primary"
          v-if="itemAmountAudit.auditStatus2 == 0"
          v-hasRole="['manager']"
          @click="submitForm4"
          >总经理提交审核</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 报销列表-->
    <el-dialog
      title="报销列表"
      :visible.sync="openreim"
      width="1280px"
      append-to-body
    >
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAddReimburse"
            v-hasPermi="['reimburse:add']"
            >报销申请</el-button
          >
        </el-col>
        <!-- <el-col :span="1.5">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-delete"
            plain
            :disabled="multiple"
            @click="handleDeleteReim"
            v-hasPermi="['reimburse:remove']"
            >删除</el-button
          >
        </el-col> -->
      </el-row>

      <el-table
        v-loading="loading"
        :data="ReimList"
        @selection-change="handleSelectionChangeReim"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="ID" prop="id" />
        <el-table-column
          label="项目名字"
          prop="itemName"
          :show-overflow-tooltip="true"
        />
        <el-table-column prop="auditStatus" label="审核状态" width="80">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.poject_auditstatus"
              :value="scope.row.auditStatus"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="驳回原因"
          prop="auditFailCause"
          :show-overflow-tooltip="true"
        />
        <el-table-column label="地区名字" align="center" prop="areaName" />
        <el-table-column label="报销人" align="center" prop="userName" />
        <el-table-column
          label="报销时间"
          align="center"
          prop="applyTime"
          width="180"
        />
        <el-table-column label="报销金额" align="center" prop="applyAmount" />
        <el-table-column
          label="报销说明"
          :show-overflow-tooltip="true"
          align="center"
          prop="applyContent"
        />
        <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
          width="180"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="200"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdateReim(scope.row)"
              v-hasPermi="['reimburse:edit']"
              >修改</el-button
            >
            <!-- <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDeleteReim(scope.row)"
              v-hasPermi="['reimburse:remove']"
              >删除</el-button
            > -->
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-dialog>
    <!-- 报销添加修改-->
    <el-dialog
      :title="titleReim"
      :visible.sync="openadd"
      width="500px"
      append-to-body
    >
      <el-form
        ref="formReim"
        :model="formReim"
        :rules="rulesReim"
        label-width="100px"
      >
        <el-form-item label="申请人" prop="userId">
          <el-select v-model="formReim.userId" placeholder="请选择">
            <el-option
              v-for="item in allList"
              :key="item.index"
              :label="item.nickName"
              :value="item.userId"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="申请时间" prop="applyTime">
          <el-date-picker
            v-model="formReim.applyTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item label="申请金额" prop="applyAmount">
          <el-input
            v-model="formReim.applyAmount"
            placeholder="请输入申请金额"
            :rows="3"
            type="number"
            oninput="value = value.replace(/[^0-9]/g,'' )"
          />
        </el-form-item>
        <el-form-item label="申请报销说明" prop="applyContent">
          <el-input
            type="textarea"
            v-model="formReim.applyContent"
            placeholder="请输入申请报销说明"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormReim">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 外包 -->
    <el-dialog
      title="项目列表"
      :visible.sync="openOut"
      width="1280px"
      append-to-body
    >
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleOuts('ADD')"
            v-hasPermi="['item:out:add']"
            >外包添加</el-button
          >
        </el-col>
        <!-- <el-col :span="1.5">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-delete"
            plain
            :disabled="multiple"
            @click="handleDeleteOut"
            v-hasPermi="['item:out:remove']"
            >删除</el-button
          >
        </el-col> -->
      </el-row>

      <el-table
        v-loading="loading"
        :data="outList"
        @selection-change="handleSelectionChangeReim"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="ID" prop="id" width="60" />
        <el-table-column
          label="项目名字"
          prop="itemName"
          :show-overflow-tooltip="true"
          width="150"
        />
        <el-table-column
          label="外包单位"
          prop="outName"
          :show-overflow-tooltip="true"
          width="150"
        />
        <el-table-column
          label="外包内容"
          prop="outContent"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="外包联系人"
          align="center"
          prop="outPerson"
          width="100"
        />
        <el-table-column
          label="外包电话"
          align="center"
          prop="outPhone"
          width="120"
        />
        <el-table-column
          label="外包时间"
          prop="outTime"
          :show-overflow-tooltip="true"
          width="150"
        />
        <el-table-column
          label="内部负责人"
          align="center"
          prop="contactUser"
          width="100"
        >
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.contactUser" :key="index">
              {{ item.userName }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="外包单位价格工程量"
          align="center"
          prop="workUnit"
          width="180"
        >
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.workUnit" :key="index">
              {{ item.price }}/{{ item.name }}/{{ item.count }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
          width="180"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="200"
          fixed="right"
        >
          <template slot-scope="scope">
            <!-- <div>
              {{scope.row.itemAudit}}
            </div> -->
            <el-button
              :disabled="
                scope.row.itemAudit.auditStatus2 == 1 ||
                (scope.row.itemAudit.auditStatus2 == 0 &&
                  scope.row.itemAudit.auditStatus1 == 1)
              "
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleOuts(scope.row)"
              v-hasPermi="['item:out:edit']"
              >修改</el-button
            >
            <!-- <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDeleteOut(scope.row)"
              v-hasPermi="['item:out:remove']"
              >删除</el-button
            > -->
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-dialog>
    <!-- 外包添加修改 -->
    <el-dialog
      :title="titleOut"
      :visible.sync="openaddOut"
      width="700px"
      append-to-body
    >
      <el-form
        ref="formOut"
        :model="formOut"
        :rules="rulesOut"
        label-width="120px"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="外包单位" prop="outId">
              <el-select
                v-model="formOut.outId"
                placeholder="请选择"
                @change="outChange"
              >
                <el-option
                  v-for="item in companylist"
                  :key="item.index"
                  :label="item.companyName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="外包时间" prop="outTime">
              <el-date-picker
                v-model="formOut.outTime"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="外包内容" prop="outContent">
            <el-input
              type="textarea"
              v-model="formOut.outContent"
              placeholder="请输入外包内容"
            />
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="外包联系人" prop="outPerson">
              <el-input
                v-model="formOut.outPerson"
                placeholder="请输入联系人"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="外包电话" prop="outPhone">
              <el-input
                v-model="formOut.outPhone"
                placeholder="请输入外包电话"
                onkeyup="this.value = this.value.replace(/[^\d]/g,'');"
                type="number"
                oninput="if(value.length>11)value=value.slice(0,11)"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="单位价格工程量" prop="workUnit">
            <el-select
              v-model="formOut.workUnit"
              placeholder="请选择"
              multiple
              value-key="id"
              @change="OutChangePrice"
            >
              <el-option
                v-for="item in unitlist"
                :key="item.index"
                :label="item.unitName"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>

          <div v-for="(item, index) in pricelist" :key="index">
            <el-row>
              <el-col :span="12">
                <el-form-item :label="item.name" width="100" prop="price">
                  <el-input v-model="item.price" placeholder="请输入价格" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="工程量" width="100" prop="count">
                  <el-input v-model="item.count" placeholder="请输入" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <el-form-item label="内部对接人" prop="contactUser">
            <el-select
              v-model="formOut.contactUser"
              placeholder="请选择"
              multiple
              value-key="id"
              @change="outTChange"
            >
              <el-option
                v-for="item in allList"
                :key="item.index"
                :label="item.nickName"
                :value="item.userId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormOut">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 项目明细-->
    <el-dialog
      title="项目明细"
      :visible.sync="openmx"
      width="500px"
      append-to-body
    >
      <el-row>
        <el-col :span="8" class="items">
          <div class="tit">人工成本</div>
          <div class="price">￥{{ priceAll.nums1 | numberToCurrency }}</div>
        </el-col>
        <el-col :span="8" class="items">
          <div class="tit">外包项目金额</div>
          <div class="price">￥{{ priceAll.nums2 | numberToCurrency }}</div>
        </el-col>
        <el-col :span="8" class="items">
          <div class="tit">项目报销金额</div>
          <div class="price">￥{{ priceAll.nums3 | numberToCurrency }}</div>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="8" class="items">
          <div class="tit">项目金额</div>
          <div class="price">￥{{ priceAll.nums6 | numberToCurrency }}</div>
        </el-col>
        <el-col :span="8" class="items">
          <div class="tit">项目总成本</div>
          <div class="price">
            ￥{{ priceAll.nums4.toFixed(2) | numberToCurrency }}
          </div>
        </el-col>
        <el-col :span="8" class="items">
          <div class="tit">项目利润</div>
          <div class="price">
            ￥{{ priceAll.nums5.toFixed(2) | numberToCurrency }}
          </div>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <Update :show.sync="dialog.updateDialogStatus" size="small"></Update>
  </div>
</template>

<script>
import Update from "./update.vue";
import {
  getProjectList,
  ProjectInfo,
  updateProject,
  addProject,
  getAreas,
  getWork,
  getUserId,
  setAudit,
  setAudit1,
  setPrice,
  setAuditPrice,
  setAuditPrice1,
  getReimburseList,
  addReimburse,
  updateReimburse,
  ReimburseInfo,
  delReimburse,
  getOutList,
  addOut,
  updateOut,
  OutInfo,
  delOut,
  getcompanyList,
  allsumber,
  uulist,
  addtc,
  settc,
  getprice,
} from "@/api/zhao/project.js";
export default {
  name: "Role",
  components: { Update },
  dicts: [
    "project_status",
    "poject_price_status",
    "poject_auditstatus",
    "poject_status_p",
  ],
  data() {
    var validatePass = (rule, value, callback) => {
      let as = this.pricelist.every((item) => {
        return item.price != "";
      });
      if (as) {
        callback();
      } else {
        callback(new Error("请输入价格"));
      }
    };
    var validatePassgc = (rule, value, callback) => {
      let as = this.pricelist.every((item) => {
        return item.count != "";
      });
      if (as) {
        callback();
      } else {
        callback(new Error("请输入工程量"));
      }
    };
    var checkPhone = (rule, value, callback) => {
      // 手机号验证
      if (!value) {
        return callback(new Error("手机号不能为空"));
      } else {
        const reg = /^1[3456789]\d{9}$/;
        if (reg.test(value)) {
          callback();
        } else {
          return callback(new Error("请输入正确的手机号"));
        }
      }
    };
    return {
      priceAll: {
        nums1: 0,
        nums2: 0,
        nums3: 0,
        nums4: 0,
        nums5: 0,
        nums6: 0,
      },
      dialog: {
        updateDialogStatus: false,
      },
      ailist: [
        {
          id: 1,
          itemStatus: "未开始",
        },
        {
          id: 2,
          itemStatus: "进行中",
        },
        {
          id: 9,
          itemStatus: "已完成",
        },
      ],
      bilist: [
        {
          id: 0,
          auditStatus: "未审核",
        },
        {
          id: 1,
          auditStatus: "审核通过",
        },
        {
          id: 2,
          auditStatus: "审核驳回",
        },
      ],
      itemAmountAudit: {},
      itemAudit: {},
      isdisabled: false,
      commissionTypelist: [
        {
          id: 1,
          name: "比例",
        },
        {
          id: 2,
          name: "固定",
        },
      ],
      auditList: [
        {
          id: 1,
          name: "审核通过",
        },
        {
          id: 2,
          name: "审核驳回",
        },
      ],
      Numbertitle: "提成金额",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: "",
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      roleOptions: [],
      // 是否显示弹出层
      open: false,
      open1: false,
      open2: false,
      openreim: false,
      openadd: false,
      openOut: false,
      openaddOut: false,
      openTC: false,
      openLook: false,
      openmx: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        areaId: undefined,
        itemName: undefined,
        itemStatus: undefined,
        customerCompanyName: undefined,
        auditStatus: undefined,
      },
      // 表单参数
      form: {},
      form1: {
        keyId: "",
        auditStatus1: "",
        auditFailCause1: "",
      },
      form2: {
        keyId: "",
        auditStatus2: "",
        auditFailCause2: "",
      },
      form3: {
        id: "",
        itemAmountUpdate: "",
        price: "",
      },
      formReim: {
        itemId: "",
        itemName: "",
        areaId: "",
        areaName: "",
        userId: "",
        userId:'',
        applyTime:'',
        applyAmount:'',
        applyContent:'',
      },
      ReimList: [],
      formOut: {
        itemId: "",
        itemName: "",
        outTime: "",
        outContent: "",
        outId: "",
        outName: "",
        outPerson: "",
        outPhone: "",
        contactUser: "",
        workUnit: "",
      },
      formtc: {},
      rulesOut: {},
      outTemlist: [],
      companylist: [],
      titleReim: "申请报销",
      titleOut: "外包添加",
      titletc: "提成添加",
      queryParamsReim: {
        pageNum: 1,
        pageSize: 10,
        areaId: undefined,
        auditStatus: undefined,
        customerCompanyName: undefined,
        itemName: undefined,
        itemStatus: undefined,
      },
      defaultProps: {
        children: "children",
        label: "label",
      },
      rulestc: {
        workUnit: [
          { required: true, message: "请选择工作单位", trigger: "blur" },
        ],
        price: [{ required: true, trigger: "blur", validator: validatePass }],
        commissionType: [
          { required: true, message: "请选择提成类型", trigger: "blur" },
        ],
        commissionNumber: [
          { required: true, message: "请输入提成价格", trigger: "blur" },
        ],
      },
      // 表单校验
      rules: {
        areaId: [
          { required: true, message: "项目地区不能为空", trigger: "blur" },
        ],
        itemName: [
          { required: true, message: "项目名字不能为空", trigger: "blur" },
        ],
        itemAmount: [
          { required: true, message: "项目金额不能为空", trigger: "blur" },
        ],
        customerCompanyName: [
          { required: true, message: "甲方单位名字不能为空", trigger: "blur" },
        ],
        // itemCooperateList: [
        //   { required: true, message: "请选择合作方", trigger: "blur" },
        // ],
      },
      rules1: {
        auditStatus1: [
          { required: true, message: "请选择审核状态", trigger: "blur" },
        ],
        auditFailCause1: [
          { required: false, message: "请输入驳回原因", trigger: "blur" },
        ],
      },
      rules2: {
        auditStatus2: [
          { required: true, message: "请选择审核状态", trigger: "blur" },
        ],
        auditFailCause2: [
          { required: false, message: "请输入驳回原因", trigger: "blur" },
        ],
      },
      rules3: {
        itemAmountUpdate: [
          { required: true, message: "请输入要修改的金额", trigger: "blur" },
        ],
      },
      rulesReim: {
        userId: [{ required: true, message: "请选择申请人", trigger: "blur" }],
        applyTime: [{ required: true, message: "请选择日期", trigger: "blur" }],
        applyAmount: [
          { required: true, message: "请输入申请金额", trigger: "blur" },
        ],
      },
      rules4: {},
      rulesOut: {
        outId: [{ required: true, message: "请选择外包单位", trigger: "blur" }],
        outTime: [
          { required: true, message: "请选择外包时间", trigger: "blur" },
        ],
        outContent: [
          { required: true, message: "请输入外包内容", trigger: "blur" },
        ],
        outPerson: [
          { required: true, message: "联系人不能为空", trigger: "blur" },
        ],
        outPhone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" },
          { validator: checkPhone, trigger: "blur" },
        ],
        workUnit: [
          { required: true, message: "单位不能为空", trigger: "blur" },
        ],
        price: [{ required: true, trigger: "blur", validator: validatePass }],
        count: [{ required: true, trigger: "blur", validator: validatePassgc }],
        contactUser: [
          { required: true, message: "内部对接人不能为空", trigger: "blur" },
        ],
      },
      tempLeader: {},
      allList: [],
      remark: [], //地区下拉列表
      unitlist: [], //单位
      pricelist: [],
      hezlist: [],
      outList: [],
      ulist: [],
      isprice: false,
      bxisshow: false,
    };
  },
  created() {
    this.getList();
    this.getAlllist();
  },
  methods: {
    look(row) {
      ProjectInfo({ id: row.id }).then((res) => {
        this.form = res.data;
        this.form.workUnit = JSON.parse(this.form.workUnit);
        this.form.temppricelist = this.form.workUnit.map((item) => item.id);
        this.pricelist = this.form.workUnit;
        this.setleaderList(this.form.itemLeaderList);
        if (this.form.itemAudit != null) {
          this.itemAudit = this.form.itemAudit;
        }
        if (this.form.itemAmountAudit != null) {
          this.itemAmountAudit = this.form.itemAmountAudit;
        }
        console.log(this.itemAudit, this.itemAmountAudit);
        this.openLook = true;
      });
    },
    addl(row) {
      this.formtc = {};
      this.formtc.isdisabled = false;
      this.openTC = true;
      this.formtc.id = row.id;
      getWork().then((res) => {
        this.unitlist = res.data;
      });
      this.pricelist = [];
    },
    submitFormtcheng() {
      this.formtc.workUnit = this.pricelist;
      this.$refs["formtc"].validate((valid) => {
        if (valid) {
          addtc(this.formtc).then((response) => {
            this.$modal.msgSuccess("添加成功");
            this.openTC = false;
            this.getList();
          });
        }
      });
    },
    //项目审核
    handleInfo(row) {
      this.titletc = "提成审核";
      ProjectInfo({ id: row.id }).then((res) => {
        this.formtc = res.data;
        console.log(this.formtc);
        this.formtc.workUnit = JSON.parse(this.formtc.workUnit);
        this.formtc.temppricelist = this.formtc.workUnit.map((item) => item.id);
        this.pricelist = this.formtc.workUnit;
        this.formtc.isdisabled = true;
        this.itemAudit = this.formtc.itemAudit;
        this.openTC = true;

        console.log(this.formtc, "------");
      });
    },
    //副总理项目审核
    submitForm1() {
      this.$refs["form1"].validate((valid) => {
        if (valid) {
          this.form1.keyId = this.formtc.id;
          setAudit(this.form1).then((res) => {
            this.openTC = false;
            this.getList();
          });
        }
      });
    },
    //总理项目审核
    submitForm2() {
      this.$refs["form2"].validate((valid) => {
        if (valid) {
          this.form2.keyId = this.formtc.id;
          setAudit1(this.form2).then((res) => {
            this.openTC = false;
            this.getList();
          });
        }
      });
    },

    getAlllist() {
      uulist().then((res) => {
        this.ulist = res.data;
      });
      getUserId({ codes: "cehui" }).then((res) => {
        this.allList.push(...res.data);
        getUserId({ codes: "sheji" }).then((res) => {
          this.allList.push(...res.data);
        });
      });
      getUserId({ codes: "hezuofang" }).then((res) => {
        this.hezlist = res.data;
      });
      getAreas().then((res) => {
        this.remark = res.data;
      });
      getWork().then((res) => {
        this.unitlist = res.data;
      });
      getcompanyList({}).then((res) => {
        this.companylist = res.data;
      });
    },
    audit(e, i) {
      if (e == 2 && i == 1) {
        this.rules1.auditFailCause1[0].required = true;
      } else {
        this.rules1.auditFailCause1[0].required = false;
      }

      if (e == 2 && i == 2) {
        this.rules2.auditFailCause2[0].required = true;
      } else {
        this.rules2.auditFailCause2[0].required = false;
      }
    },
    postChange(e) {
      if (e == 1) {
        this.Numbertitle = "提成比例(%)";
        this.rulestc.commissionNumber[0].message = "请输入提成比例";
      } else {
        this.Numbertitle = "提成金额";
        this.rulestc.commissionNumber[0].message = "请输入提成价格";
      }
    },
    remarkAllchange(e) {
      this.form.areaName =
        this.remark[this.remark.findIndex((item) => item.id === e)].areaName;
    },
    unitcahnge(ids) {
      if (ids.length == 0) {
        this.pricelist = [];
      } else {
        ids.forEach((v, i) => {
          var index = this.pricelist.findIndex((item) => item.id === v);
          if (index == -1) {
            //说明arr中不存在id为objid的对象
            this.pricelist.push({
              id: v,
              name: this.unitlist.filter((unit) => unit.id == v)[0].unitName,
              price: "",
            });
          } else {
            this.pricelist = this.pricelist.filter((item) => {
              if (ids.indexOf(item.id) > -1) {
                return item;
              }
            });
          }
        });
      }
    },
    allchange(ids, key, t1, t2, t3) {
      this.$forceUpdate();
      let num = [];
      ids.forEach((v, i) => {
        num.push({
          leaderUserId: v,
          leaderUserName: this.ulist.filter((user) => user.userId == v)[0]
            .userName,
          leaderTypeOne: t1,
          leaderTypeTwo: t2,
          leaderTypeThree: t3,
        });
      });
      this.tempLeader[key] = num;
    },
    // 表单重置
    reset() {
      this.pricelist = [];
      this.resetForm("form");
      this.resetForm("formOut");
    },
    getList() {
      this.loading = true;
      getProjectList(this.queryParams).then((res) => {
        this.roleList = res.rows;
        this.roleList.forEach((item) => {
          item.workUnit = JSON.parse(item.workUnit);
        });
        this.total = res.total;
        this.loading = false;
      });
    },

    resetQuery() {
      this.resetForm("queryForm");
      this.getList();
    },
    setleaderList(mapList) {
      mapList.forEach((item) => {
        let key = `k${item.leaderTypeOne}${item.leaderTypeTwo}${item.leaderTypeThree}_list`;
        if (!this.form[key]) {
          this.form[key] = [];
        }
        this.form[key].push(item.leaderUserId);
      });
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.multiple = !selection.length;
    },
    handleSelectionChangeReim(selection) {
      this.ids = selection.map((item) => item.id);
      this.multiple = !selection.length;
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.open1 = false;
      this.open2 = false;
      this.openadd = false;
      this.openaddOut = false;
      this.openTC = false;
      this.openLook = false;
      this.openmx = false;
      this.reset();
    },

    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    // 项目新增提交按钮
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            this.form.workUnit = JSON.stringify(this.pricelist);
            let alllist = [];
            Object.keys(this.tempLeader).forEach((key) => {
              alllist.push(...this.tempLeader[key]);
            });
            this.form.itemLeaderList = alllist;
            this.form.itemCooperateList = this.form.itemCooperateList.map(
              (item) => {
                return {
                  userId: item,
                };
              }
            );
            updateProject(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.workUnit = JSON.stringify(this.pricelist);
            let alllist = [];
            Object.keys(this.tempLeader).forEach((key) => {
              alllist.push(...this.tempLeader[key]);
            });
            this.form.itemLeaderList = alllist;
            this.form.itemCooperateList = this.form.itemCooperateList.map(
              (item) => {
                return {
                  userId: item,
                };
              }
            );
            addProject(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //项目列表导出
    handleExport() {
      this.download(
        "item/export",
        {
          ...this.queryParams,
        },
        `user_${new Date().getTime()}.xlsx`
      );
    },
    // 项目新增按钮
    handleAdd() {
      this.reset();
      this.form = {};
      this.open = true;
      this.isprice = false;
      this.title = "添加项目";
    },
    //项目修改
    handleUpdate(row) {
      this.open = true;
      this.title = "项目修改";
      this.isprice = true;
      const postId = row.id || this.ids;
      ProjectInfo({ id: postId }).then((res) => {
        this.form = res.data;
        this.form.workUnit = JSON.parse(this.form.workUnit);
        this.form.temppricelist = this.form.workUnit.map((item) => item.id);
        this.pricelist = this.form.workUnit;
        this.setleaderList(this.form.itemLeaderList);
        this.open = true;
        console.log(this.form);
      });
    },

    //项目修改金额
    handlePrice(row) {
      const postId = row.id || this.ids;
      ProjectInfo({ id: postId }).then((res) => {
        this.form = res.data;
        this.form3.price = res.data.itemAmount;
        this.open1 = true;
      });
    },
    //修改金额提交按钮
    submitFormPrices() {
      this.$refs["form3"].validate((valid) => {
        if (valid) {
          this.form3.id = this.form.id;
          setPrice(this.form3).then((res) => {
            this.open1 = false;
            this.getList();
          });
        }
      });
    },
    //金额审核按钮
    handlePriceAudit(row) {
      const postId = row.id || this.ids;
      ProjectInfo({ id: postId }).then((res) => {
        this.form = res.data;
        this.form.workUnit = JSON.parse(this.form.workUnit);
        this.form.temppricelist = this.form.workUnit.map((item) => item.id);
        this.pricelist = this.form.workUnit;
        this.setleaderList(this.form.itemLeaderList);
        this.itemAmountAudit = this.form.itemAmountAudit;
        this.open2 = true;
      });
    },
    //副总理项目审核
    submitForm3() {
      this.$refs["form1"].validate((valid) => {
        if (valid) {
          this.form1.keyId = this.form.id;
          setAuditPrice(this.form1).then((res) => {
            this.open2 = false;
            this.getList();
          });
        }
      });
    },
    //总理项目审核
    submitForm4() {
      this.$refs["form2"].validate((valid) => {
        if (valid) {
          this.form2.keyId = this.form.id;
          setAuditPrice1(this.form2).then((res) => {
            this.open2 = false;
            this.getList();
          });
        }
      });
    },
    //报销按钮
    handleReimburse(row) {
      this.openreim = true;
      this.queryParamsReim.itemId = row.id;
      this.formReim.areaId = row.areaId;
      this.formReim.areaName = row.areaName;
      this.formReim.itemId = row.id;
      this.formReim.itemName = row.itemName;
      this.loading = true;
      getReimburseList(this.queryParamsReim).then((res) => {
        this.ReimList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    //添加报销按钮
    handleAddReimburse() {
      this.titleReim = "报销添加";
      this.bxisshow = false;
      this.openadd = true;
      this.formReim.applyAmount = "";
      this.formReim.applyContent = "";
      this.formReim.applyTime = "";
      this.formReim.userId = "";
    },
    //修改
    handleUpdateReim(row) {
      this.bxisshow = true;
      this.titleReim = "报销修改";
      this.openadd = true;
      ReimburseInfo({ id: row.id }).then((res) => {
        this.formReim = res.data;
        this.openadd = true;
      });
    },

    //删除按钮
    handleDeleteReim(row) {
      let postIds = "";
      if (row.id) {
        postIds = [row.id];
      } else {
        postIds = this.ids;
      }
      this.$modal
        .confirm('是否确认删除id编号为"' + postIds + '"的数据项？')
        .then(function () {
          delReimburse({ ids: postIds }).then((res) => {
            this.$modal.msgSuccess("删除成功");
          });
        })
        .then(() => {
          this.loading = true;
          getReimburseList(this.queryParamsReim).then((res) => {
            this.ReimList = res.rows;
            this.total = res.total;
            this.loading = false;
          });
        })
        .catch(() => {});
    },
    //提交按钮
    submitFormReim() {
      this.$refs["formReim"].validate((valid) => {
        if (valid) {
          if (this.bxisshow) {
            console.log("修改", this.formReim);
            updateReimburse(this.formReim).then((response) => {
              this.$modal.msgSuccess("修改成功");
              getReimburseList(this.queryParamsReim).then((res) => {
                this.ReimList = res.rows;
                this.total = res.total;
              });
              this.openadd = false;
            });
          } else {
            //报销申请
            this.formReim.userName = this.allList.filter(
              (user) => user.userId == this.formReim.userId
            )[0].nickName;
            addReimburse(this.formReim).then((res) => {
              this.loading = true;
              this.$modal.msgSuccess("新增成功");
              getReimburseList(this.queryParamsReim).then((res) => {
                this.ReimList = res.rows;
                this.total = res.total;
                this.loading = false;
                this.formReim.applyAmount = "";
                this.formReim.applyContent = "";
                this.formReim.applyTime = "";
                this.formReim.userId = "";
              });
              this.openadd = false;
            });
          }
        }
      });
    },

    //项目外包按钮
    handleOut(row) {
      this.openOut = true;
      this.queryParamsReim.itemId = row.id;
      this.formOut.itemId = row.id;
      this.formOut.itemName = row.itemName;
      getWork().then((res) => {
        this.unitlist = res.data;
      });
      this.loading = true;
      getOutList(this.queryParamsReim).then((res) => {
        this.outList = res.rows;
        this.outList.forEach((item) => {
          item.workUnit = JSON.parse(item.workUnit);
          item.contactUser = JSON.parse(item.contactUser);
        });
        this.total = res.total;
        this.loading = false;
      });
    },
    //外包单位 change事件
    outChange(e) {
      console.log(e);
      this.formOut.outName = this.companylist.filter(
        (user) => user.id == e
      )[0].companyName;
      this.formOut.outPerson = this.companylist.filter(
        (user) => user.id == e
      )[0].companyPerson;
      this.formOut.outPhone = this.companylist.filter(
        (user) => user.id == e
      )[0].companyPhone;
    },
    outTChange(ids) {
      let num = [];
      ids.forEach((v, i) => {
        num.push({
          userId: v,
          userName: this.allList.filter((user) => user.userId == v)[0].nickName,
        });
      });
      this.outTemlist = num;
    },
    //外包单位 价格 工程量 change事件
    OutChangePrice(ids) {
      if (ids.length == 0) {
        this.pricelist = [];
      } else {
        ids.forEach((v, i) => {
          var index = this.pricelist.findIndex((item) => item.id === v);
          if (index == -1) {
            //说明arr中不存在id为objid的对象
            this.pricelist.push({
              id: v,
              name: this.unitlist.filter((unit) => unit.id == v)[0].unitName,
              price: "",
              count: "",
            });
          } else {
            this.pricelist = this.pricelist.filter((item) => {
              if (ids.indexOf(item.id) > -1) {
                return item;
              }
            });
          }
        });
        console.log(this.pricelist);
      }
    },
    //项目外包添加修改
    handleOuts(ts) {
      if (ts == "ADD") {
        this.openaddOut = true;
        this.formOut.isshow = false;
      } else {
        this.openaddOut = true;
        OutInfo({ id: ts.id }).then((res) => {
          this.formOut = res.data;
          this.pricelist = JSON.parse(this.formOut.workUnit);
          this.formOut.workUnit = this.pricelist.map((item) => item.id);
          this.formOut.contactUser = JSON.parse(this.formOut.contactUser);
          this.formOut.contactUser = this.formOut.contactUser.map(
            (item) => item.userId
          );
          this.formOut.isshow = true;
          console.log(this.formOut, "------");
        });
      }
    },
    //项目外包删除
    handleDeleteOut(row) {
      let postIds = "";
      if (row.id) {
        postIds = [row.id];
      } else {
        postIds = this.ids;
      }
      this.$modal
        .confirm('是否确认删除id编号为"' + postIds + '"的数据项？')
        .then(function () {
          delOut({ ids: postIds }).then((res) => {
            console.log(res);
            this.$modal.msgSuccess("删除成功");
          });
        })
        .then(() => {
          this.loading = true;
          getOutList(this.queryParamsReim).then((res) => {
            this.outList = res.rows;
            this.outList.forEach((item) => {
              item.workUnit = JSON.parse(item.workUnit);
              item.contactUser = JSON.parse(item.contactUser);
            });
            this.total = res.total;
            this.loading = false;
          });
        })
        .catch(() => {});
    },
    // 外包项目提交按钮
    submitFormOut() {
      this.$refs["formOut"].validate((valid) => {
        if (valid) {
          if (this.formOut.isshow) {
            this.formOut.contactUser = JSON.stringify(this.outTemlist);
            this.formOut.workUnit = JSON.stringify(this.pricelist);
            updateOut(this.formOut).then((response) => {
              this.$modal.msgSuccess("修改成功");
              getOutList(this.queryParamsReim).then((res) => {
                this.outList = res.rows;
                this.outList.forEach((item) => {
                  item.workUnit = JSON.parse(item.workUnit);
                  item.contactUser = JSON.parse(item.contactUser);
                });
                this.total = res.total;
                this.loading = false;
              });
              this.openaddOut = false;
              this.reset();
            });
          } else {
            this.formOut.contactUser = JSON.stringify(this.outTemlist);
            this.formOut.workUnit = JSON.stringify(this.pricelist);
            console.log(this.formOut);

            addOut(this.formOut).then((res) => {
              this.loading = true;
              this.$modal.msgSuccess("新增成功");
              getOutList(this.queryParamsReim).then((res) => {
                this.outList = res.rows;
                this.outList.forEach((item) => {
                  item.workUnit = JSON.parse(item.workUnit);
                  item.contactUser = JSON.parse(item.contactUser);
                });
                this.total = res.total;
                this.loading = false;
              });
              this.openaddOut = false;
              this.reset();
            });
          }
        }
      });
    },
    // 项目完成按钮
    handleAllyes(row) {
      this.$modal
        .confirm("项目名称为：" + row.itemName + "是否要完成？")
        .then(function () {
          allsumber({ id: row.id }).then((res) => {
            console.log(res);
          });
        })
        .then(() => {
          this.$modal.msgSuccess("操作成功");
          this.getList();
        })
        .catch(() => {});
    },
    //项目明细
    lookxm(row) {
      getprice({ id: row.id }).then((res) => {
        this.priceAll.nums1 = res.data.cost.sum;
        this.priceAll.nums2 = res.data.itemOut.sum;
        this.priceAll.nums3 = res.data.reimburse.sum;
        this.priceAll.nums4 =
          res.data.cost.sum + res.data.itemOut.sum + res.data.reimburse.sum;
        this.priceAll.nums5 = res.data.itemAmount - this.priceAll.nums4;
        this.priceAll.nums6 = res.data.itemAmount;

        this.openmx = true;
      });
    },
  },
};
</script>
<style lang="scss">
.img {
  width: 120px;
  height: 60px;
}
.text {
  font-size: 16px;
  font-weight: bold;
  margin-left: 24px;
  margin-bottom: 10px;
}
.items {
  .tit {
    font-size: 18px;
    color: #000000;
  }
  .price {
    font-size: 16px;
    margin-top: 6px;
  }
  margin-bottom: 20px;
}
.itemss {
  margin: 10px 0px;
  .tit {
    font-size: 18px;
    color: #000000;
  }
  .price {
    font-size: 16px;
    margin-top: 6px;
  }
}
</style>
